{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $foo == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('category', array('foo' => 'post'))}">添加分类</a></li>
	<li {if $foo == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('category', array('foo' => 'display'))}">管理分类</a></li>
</ul>
{if $foo == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit="return check(this)">
	<input type="hidden" name="parentid" value="{$parent['id']}" />
		<h4>分类详细设置</h4>
		<table class="tb">

      {if !empty($category['name'])}
      <div class="form-group">
        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">访问地址</label>
        <div class="col-sm-8 col-xs-12">
          <a class="preview_url" href="{php echo $_W['siteroot'] . 'app/' . $this->createMobileUrl('list', array('cid' => $category['id'], 'weid' => $_W['weid']))}" target="_blank">{php echo $this->createMobileUrl('list', array('cid' => $category['id'], 'weid' => $_W['weid']))}</a>
          <span class="help-block">您可以根据此地址，添加回复规则，设置访问。鼠标移动到链接上可显示本文二维码。注意：本二维码仅供预览，分享不送积分。</span>
        </div>
      </div>
      {/if}

			{if !empty($parentid)}
      <div class="form-group">
        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">上级分类</label>
        <div class="col-sm-8 col-xs-12">
					{$parent['name']}
        </div>
      </div>
			{/if}

      <div class="form-group">
        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">排序</label>
        <div class="col-sm-8 col-xs-12">
          <input type="text" class="form-control" placeholder="" name="displayorder" value="{$category['displayorder']}">
          <span class="help-block">二级列表的显示顺序，越大则越靠前</span>
        </div>
      </div>

      <div class="form-group">
        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">分类名称</label>
        <div class="col-sm-8 col-xs-12">
          <input type="text" class="form-control" placeholder="" name="cname" value="{$category['name']}">
        </div>
      </div>

      <div class="form-group">
				<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">分类描述</label>
        <div class="col-sm-8 col-xs-12">
          <textarea name="description" class="form-control" rows="5">{$category['description']}</textarea>
        </div>
      </div>
      <div class="form-group">
        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">分类图片</label>
        <div class="col-sm-8 col-xs-12">
          {php echo tpl_form_field_image('thumb', $category['thumb']);}
        </div>
      </div>

      <div class="form-group">
        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">选择分类模板</label>
        <div class="col-sm-8 col-xs-12">
          {template 'category_template'}
        </div>
      </div>

      <div class="form-group">
				<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">直接链接</label>
        <div class="col-sm-8 col-xs-12">
          <input type="text" class="form-control" placeholder="" name="linkurl" value="{$category['linkurl']}">
          <span class="help-block">链接必须是以http://或是https://开头</span>
        </div>
      </div>
      <div class="form-group">
        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"></label>
        <div class="col-sm-8 col-xs-12">
          <input name="submit" type="submit" value="提交" class="btn btn-primary">
          <input type="hidden" name="token" value="{$_W['token']}" />
        </div>
      </div>
    </form>
  </div>

<script type="text/javascript">
  function formcheck() {
    return true;
  }
<!--
	function getTemplateFiles(obj) {
		$('#file').empty();
		$('#file').append('<option value="">请选择分类模板文件</option>');
		if (!$(obj).val()) {
			return false;
		}

		$.getJSON('{php echo $this->createWebUrl('category', array('foo' => 'templatefiles'))}', {'template' : $(obj).val(), 'ishomepage' : $('input[name="ishomepage"]:checked').val() == '1' ? 1 : 0}, function(s){
			if (s.message.status != 0) {
				message(s.message.message, '', 'error');
				return;
			}
			$('#file').empty();
			if (s.message.message) {
				for (i in s.message.message) {
					$('#file').append('<option value="'+s.message.message[i]+'">'+s.message.message[i]+'</option>');
				}
			} 
		});
	}

	function check(form) {
		if (!form['cname'].value) {
			message('请输入分类名称！', '', 'error');
			return false;
		}
		if (!$('input[name="ishomepage"]:checked').val() && form['template'].value && !form['file'].value) {
			message('请指定分类模板文件', '', 'error');
			return false;
		}
	}

	function restoreDefaultItem() {
		$("#template option[value='']").attr('selected', true);
		$('#file').empty();
		$('#file').append('<option value="">请选择分类模板文件</option>');
	}
//-->
</script>
{elseif $foo == 'display'}
<div class="main">
	<div class="category">
		<form action="" method="post" onsubmit="return formcheck(this)">
		<table class="table table-hover">
			<thead>
				<tr>
					<th style="width:50px;">显示顺序</th>
					<th>分类名称</th>
					<th>链接</th>
					<th style="width:80px;">设为栏目</th>
					<th style="width:120px;">操作</th>
				</tr>
			</thead>
      <tbody>
      {loop $category $row}
        <tr>
          <td class="text-center"><input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}"></td>
          <td class="text-left"><div style="height:30px;line-height:30px">
            <a href="{php echo $this->createUrl('list', array('cid' => $row['id'], 'weid' => $_W['weid']))}" target="_blank">
            {$row['name']}
            </a>
            &nbsp;&nbsp;{if empty($row['parentid'])}<a href="{php echo $this->createWebUrl('category', array('foo' => 'post', 'parentid' => $row['id']))}" title="添加子分类"><i class="fa fa-plus"></i></a>{/if}</div></td>
          <td class="text-center"><input type="text" class="form-control" value="{php echo $this->createMobileUrl('list', array('cid' => $row['id'], 'weid' => $_W['weid']))}"></td>
          <td class="text-center">{php echo $row['nid'] ? '是' : '否'}</td>
          <td class="text-center">
            <a href="{php echo $this->createWebUrl('article', array('foo' => 'post', 'pcate' => $row['id']))}" title="添加文章" class="btn btn-default btn-sm"  data-toggle="tooltip" data-placement="top"><i class="fa fa-plus"></i></a>
            <a href="{php echo $this->createWebUrl('category', array('foo' => 'post', 'id' => $row['id']))}" title="编辑" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-edit"></i></a>
            <a href="{php echo $this->createWebUrl('category', array('foo' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" title="删除" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"></i></a>
          </td>
        </tr>
        {loop $children[$row['id']] $row}
        <tr>
          <td class="text-center"><input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}"></td>
          <td class="text-left"><div style="padding-left:50px;height:30px;line-height:30px;background:url('./resource/images/bg_repno.gif') no-repeat -245px -545px;">{$row['name']}&nbsp;&nbsp;{if empty($row['parentid'])}<a href="{php echo $this->createWebUrl('category', array('foo' => 'post', 'parentid' => $row['id']))}"><i class="fa fa-plus" title="添加子分类"></i></a>{/if}</div></td>
          <td class="text-center"><input type="text" class="form-control" value="{php echo $this->createMobileUrl('list', array('cid' => $row['id'], 'weid' => $_W['weid']))}"></td>
          <td class="text-center">{php echo $row['enabled'] ? '是' : '否'}</td>
          <td class="text-center">
            <a href="{php echo $this->createWebUrl('article', array('foo' => 'post', 'pcate' => $row['id']))}" title="添加文章" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-plus"></i></a>
            <a href="{php echo $this->createWebUrl('category', array('foo' => 'post', 'id' => $row['id']))}" title="编辑" class="btn btn-default btn-sm"><i class="fa fa-edit" data-toggle="tooltip" data-placement="top"></i></a>
            <a href="{php echo $this->createWebUrl('category', array('foo' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" title="删除" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"></i></a>
          </td>
        </tr>
        {/loop}
      {/loop}
        <tr>
          <td colspan="5">
            <a href="{php echo $this->createWebUrl('category', array('foo'=>'post'));}"><i class="fa fa-plus-circle" title="添加新分类"></i> 添加新分类</a>
          </td>
        </tr>

				<tr>
					<td></td>
					<td colspan="5">
						<input name="submit" type="submit" class="btn btn-primary" value="提交">
						<input type="hidden" name="token" value="{$_W['token']}" />
					</td>
				</tr>
			</tbody>
		</table>
		</form>
	</div>
</div>
{/if}
<script>
  $('.btn').hover(function(){
    $(this).tooltip('show');
    },function(){
    $(this).tooltip('hide');
  });
  $('.full').hover(function(){
    $(this).tooltip('show');
    },function(){
    $(this).tooltip('hide');
  });
</script>

{template 'common/footer'}
